Fix alignment tracking in VectorReduce::Add simplifier (#9100)#9104
Merged
Fix alignment tracking in VectorReduce::Add simplifier (#9100)#9104
Conversation
The bounds-and-alignment analysis for horizontal add was scaling the
bounds by the reduction factor but leaving alignment untouched. For an
argument whose lanes all had alignment {2, 1} (odd), the horizontal add
result was still marked {2, 1}, when in fact the sum of factor odd
lanes has alignment {2, factor mod 2}. A later cast<uint1> would then
use the stale alignment to trim [0, 1] down to a single point and
fold the expression to a wrong constant.
Fix it by adding the per-lane alignment to itself factor times, which
produces the right modulus (it does not shrink) and remainder. Do the
same for SaturatingAdd when saturation cannot clip.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
alexreinking
requested changes
Apr 22, 2026
Member
alexreinking
left a comment
There was a problem hiding this comment.
Can you please ask Claude to add a regression test for this case? It wasn't easy to find through fuzzing.
Covers the fuzzer finding that motivated 71dbcef: cast<uint1> of a horizontal add whose lanes all have known odd alignment was being folded to the wrong constant because the alignment was not scaled across the reduction. Uses a select of broadcasts (which does not match any VectorReduce::Add rewrite rule) so the check actually goes through the info-update path rather than being constant-folded earlier. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
alexreinking
approved these changes
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bounds-and-alignment analysis for horizontal add was scaling the bounds by the reduction factor but leaving alignment untouched. For an argument whose lanes all had alignment {2, 1} (odd), the horizontal add result was still marked {2, 1}, when in fact the sum of factor odd lanes has alignment {2, factor mod 2}. A later cast would then use the stale alignment to trim [0, 1] down to a single point and fold the expression to a wrong constant.
Fix it by adding the per-lane alignment to itself factor times, which produces the right modulus (it does not shrink) and remainder. Do the same for SaturatingAdd when saturation cannot clip.
Fixes #9100